package org.testis.gui.mvc.view.dynamicmap;

import org.testis.gui.mvc.view.*;
import org.testis.gui.mvc.utilities.Validatable;
import org.testis.gui.mvc.controller.DynamicMapControllerList;
import org.testis.gui.mvc.controller.dynamicmap.DynamicMapController;
import org.testis.gui.mvc.controller.dynamicmap.WebPageParserController;
import org.testis.gui.mvc.utilities.PageParserObject;
import org.testis.utils.tree.MyDefaultMutableTreeNode;
import java.awt.Frame;
import java.awt.event.WindowListener;
import java.beans.PropertyChangeEvent;
import java.util.LinkedList;
import javax.swing.JOptionPane;

/**
 *
 * @author  nurhat
 */
public class WebPageParserView extends AtofBaseDialog
        implements AbstractViewPanel, Validatable {

    private static final long serialVersionUID = 1231222L;
    private String m_windowTitle;
    private boolean m_editMode = false;

    /** Creates new form WebPageParserView */
    public WebPageParserView(Frame parent,
            boolean modal,
            boolean editMode) {
        super(parent,
                modal);
        m_editMode = editMode;
        if (editMode) {
            m_windowTitle = "Edit WebPageParserView";
        } else {
            m_windowTitle = "Add WebPageParserView";
        }
        setTitle(m_windowTitle);
        initComponents();
        InitializeCombos();
    }

    public void InitializeCombos() {
        choiceBrowserType.addItem("chrome");
        choiceBrowserType.addItem("iehta");
        choiceBrowserType.select("chrome");
        choiceObjectType.add("UIAll");
        choiceObjectType.add("UIFrame");
        choiceObjectType.add("UITextBox");
        choiceObjectType.add("UIFileSelector");
        choiceObjectType.add("UIButton");
        choiceObjectType.add("UILink");
        choiceObjectType.add("UIMultiSelectListBox");
        choiceObjectType.add("UIDropDown");
        choiceObjectType.add("UICheckBox");
        choiceObjectType.add("UICheckBoxGroup");
        choiceObjectType.add("UIRadioButton");
        choiceObjectType.add("UIRadioButtonGroup");
        choiceObjectType.add("UILabel");
        choiceObjectType.add("UITextArea");

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlNavigation = new java.awt.Panel();
        lblNavigation = new java.awt.Label();
        lblSelectBrowser = new java.awt.Label();
        btnEndNavigation = new java.awt.Button();
        btnStartNavigation = new java.awt.Button();
        txtAddress = new java.awt.TextField();
        choiceBrowserType = new java.awt.Choice();
        lblPageNavigationHeader = new java.awt.Label();
        pnlSearchObject = new java.awt.Panel();
        lblObjectType = new java.awt.Label();
        lblSelectBrowser1 = new java.awt.Label();
        btnSelectFrame = new java.awt.Button();
        btnGetObjects = new java.awt.Button();
        txtSelectFrame = new java.awt.TextField();
        choiceObjectType = new java.awt.Choice();
        lblSearchObjectHeader = new java.awt.Label();
        pnlOutput = new java.awt.Panel();
        lblOutputHeader = new java.awt.Label();
        txtOutput = new java.awt.TextArea();
        btnProcessOutput = new java.awt.Button();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        lblNavigation.setFont(new java.awt.Font("Dialog", 1, 11));
        lblNavigation.setName("lblNavigation"); // NOI18N
        lblNavigation.setText("Navigate:");

        lblSelectBrowser.setFont(new java.awt.Font("Dialog", 1, 11));
        lblSelectBrowser.setName("lblSelectBrowser"); // NOI18N
        lblSelectBrowser.setText("Select Browser:");

        btnEndNavigation.setEnabled(false);
        btnEndNavigation.setFont(new java.awt.Font("Dialog", 0, 11));
        btnEndNavigation.setLabel("End Navigation");
        btnEndNavigation.setName("btnEndNavigation"); // NOI18N
        btnEndNavigation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEndNavigationActionPerformed(evt);
            }
        });

        btnStartNavigation.setFont(new java.awt.Font("Dialog", 0, 11));
        btnStartNavigation.setLabel("Start Navigation");
        btnStartNavigation.setName("btnStartNavigation"); // NOI18N
        btnStartNavigation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStartNavigationActionPerformed(evt);
            }
        });

        txtAddress.setFont(new java.awt.Font("Dialog", 0, 11));
        txtAddress.setName("txtAddress"); // NOI18N
        txtAddress.setText("http://192.168.2.1");
        txtAddress.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtAddressActionPerformed(evt);
            }
        });

        choiceBrowserType.setFont(new java.awt.Font("Dialog", 0, 11));
        choiceBrowserType.setName("choiceBrowserType"); // NOI18N
        choiceBrowserType.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                choiceBrowserTypeItemStateChanged(evt);
            }
        });

        lblPageNavigationHeader.setBackground(new java.awt.Color(232, 223, 223));
        lblPageNavigationHeader.setFont(new java.awt.Font("Dialog", 1, 12));
        lblPageNavigationHeader.setName("lblPageNavigationHeader"); // NOI18N
        lblPageNavigationHeader.setText("  Page Navigation");

        javax.swing.GroupLayout pnlNavigationLayout = new javax.swing.GroupLayout(pnlNavigation);
        pnlNavigation.setLayout(pnlNavigationLayout);
        pnlNavigationLayout.setHorizontalGroup(
            pnlNavigationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlNavigationLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlNavigationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlNavigationLayout.createSequentialGroup()
                        .addGroup(pnlNavigationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(lblNavigation, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblSelectBrowser, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(2, 2, 2)
                        .addGroup(pnlNavigationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(pnlNavigationLayout.createSequentialGroup()
                                .addComponent(btnEndNavigation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(2, 2, 2)
                                .addComponent(btnStartNavigation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(txtAddress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(choiceBrowserType, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(lblPageNavigationHeader, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE))
                .addContainerGap())
        );
        pnlNavigationLayout.setVerticalGroup(
            pnlNavigationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlNavigationLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblPageNavigationHeader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(6, 6, 6)
                .addGroup(pnlNavigationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblSelectBrowser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(choiceBrowserType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlNavigationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblNavigation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlNavigationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnEndNavigation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnStartNavigation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        lblObjectType.setFont(new java.awt.Font("Dialog", 1, 11));
        lblObjectType.setName("lblObjectType"); // NOI18N
        lblObjectType.setText("Object Type:");

        lblSelectBrowser1.setFont(new java.awt.Font("Dialog", 1, 11));
        lblSelectBrowser1.setName("lblSelectBrowser"); // NOI18N
        lblSelectBrowser1.setText("Select Frame:");

        btnSelectFrame.setEnabled(false);
        btnSelectFrame.setFont(new java.awt.Font("Dialog", 0, 11));
        btnSelectFrame.setLabel("Select Frame");
        btnSelectFrame.setName("btnSelectFrame"); // NOI18N
        btnSelectFrame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSelectFrameActionPerformed(evt);
            }
        });

        btnGetObjects.setEnabled(false);
        btnGetObjects.setFont(new java.awt.Font("Dialog", 0, 11));
        btnGetObjects.setLabel("Get Objects");
        btnGetObjects.setName("btnGetObjects"); // NOI18N
        btnGetObjects.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGetObjectsActionPerformed(evt);
            }
        });

        txtSelectFrame.setFont(new java.awt.Font("Dialog", 0, 11));
        txtSelectFrame.setName("txtSelectFrame"); // NOI18N
        txtSelectFrame.setText("mainFrame");
        txtSelectFrame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSelectFrameActionPerformed(evt);
            }
        });

        choiceObjectType.setFont(new java.awt.Font("Dialog", 0, 11));
        choiceObjectType.setName("choiceObjectType"); // NOI18N
        choiceObjectType.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                choiceObjectTypeItemStateChanged(evt);
            }
        });

        lblSearchObjectHeader.setBackground(new java.awt.Color(232, 223, 223));
        lblSearchObjectHeader.setFont(new java.awt.Font("Dialog", 1, 12));
        lblSearchObjectHeader.setName("lblSearchObjectHeader"); // NOI18N
        lblSearchObjectHeader.setText("Search Object");

        javax.swing.GroupLayout pnlSearchObjectLayout = new javax.swing.GroupLayout(pnlSearchObject);
        pnlSearchObject.setLayout(pnlSearchObjectLayout);
        pnlSearchObjectLayout.setHorizontalGroup(
            pnlSearchObjectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlSearchObjectLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlSearchObjectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblSearchObjectHeader, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE)
                    .addGroup(pnlSearchObjectLayout.createSequentialGroup()
                        .addGroup(pnlSearchObjectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(lblObjectType, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblSelectBrowser1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlSearchObjectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(choiceObjectType, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtSelectFrame, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlSearchObjectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(btnSelectFrame, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnGetObjects, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 116, Short.MAX_VALUE)))
                .addContainerGap())
        );
        pnlSearchObjectLayout.setVerticalGroup(
            pnlSearchObjectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlSearchObjectLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblSearchObjectHeader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlSearchObjectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pnlSearchObjectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lblSelectBrowser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtSelectFrame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnSelectFrame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlSearchObjectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblObjectType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(choiceObjectType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addComponent(btnGetObjects, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        pnlOutput.setName("pnlOutput"); // NOI18N

        lblOutputHeader.setBackground(new java.awt.Color(232, 223, 223));
        lblOutputHeader.setFont(new java.awt.Font("Dialog", 1, 12));
        lblOutputHeader.setName("lblOutputHeader"); // NOI18N
        lblOutputHeader.setText("Output");

        txtOutput.setEditable(false);

        btnProcessOutput.setEnabled(false);
        btnProcessOutput.setLabel("Process Output");
        btnProcessOutput.setName("btnProcessOutput"); // NOI18N
        btnProcessOutput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProcessOutputActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlOutputLayout = new javax.swing.GroupLayout(pnlOutput);
        pnlOutput.setLayout(pnlOutputLayout);
        pnlOutputLayout.setHorizontalGroup(
            pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlOutputLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtOutput, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE)
                    .addComponent(lblOutputHeader, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE)
                    .addComponent(btnProcessOutput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        pnlOutputLayout.setVerticalGroup(
            pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlOutputLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblOutputHeader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtOutput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnProcessOutput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(pnlOutput, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlNavigation, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlSearchObject, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlNavigation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlSearchObject, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlOutput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void btnStartNavigationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartNavigationActionPerformed
//GEN-LAST:event_btnStartNavigationActionPerformed
        choiceBrowserTypeItemStateChanged(null);
        txtAddressActionPerformed(null);
        DynamicMapControllerList.newInstance().getWebPageParserController().
                operationChangeNavigating(true);
    }

private void btnEndNavigationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEndNavigationActionPerformed

    DynamicMapControllerList.newInstance().getWebPageParserController().
            operationChangeNavigating(false);
}//GEN-LAST:event_btnEndNavigationActionPerformed

private void btnSelectFrameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectFrameActionPerformed
    try {
        DynamicMapControllerList.newInstance().getWebPageParserController().
                operationChangeSelectedFrame(txtSelectFrame.getText());
    } catch (Exception e) {
    }
}//GEN-LAST:event_btnSelectFrameActionPerformed

private void btnGetObjectsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGetObjectsActionPerformed
    choiceObjectTypeItemStateChanged(null);
    try {
        DynamicMapControllerList.newInstance().getWebPageParserController().
                operationChangeSelectedObjects();
    } catch (Exception e) {
    }

}//GEN-LAST:event_btnGetObjectsActionPerformed

private void choiceBrowserTypeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_choiceBrowserTypeItemStateChanged
    try {
        DynamicMapControllerList.newInstance().getWebPageParserController().
                operationChangeBrowserType(choiceBrowserType.getSelectedItem());
    } catch (Exception e) {
    }
}//GEN-LAST:event_choiceBrowserTypeItemStateChanged

private void txtAddressActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtAddressActionPerformed
    try {
        DynamicMapControllerList.newInstance().getWebPageParserController().
                operationChangeDeviceAddress(
                txtAddress.getText());
    } catch (Exception e) {
    }
}//GEN-LAST:event_txtAddressActionPerformed

private void txtSelectFrameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSelectFrameActionPerformed
}//GEN-LAST:event_txtSelectFrameActionPerformed

private void choiceObjectTypeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_choiceObjectTypeItemStateChanged
    try {//GEN-LAST:event_choiceObjectTypeItemStateChanged
            DynamicMapControllerList.newInstance().getWebPageParserController().
                    operationChangeObjectType(choiceObjectType.getSelectedItem());
        } catch (Exception e) {
        }
    }
private void btnProcessOutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProcessOutputActionPerformed
    try {
        DynamicMapControllerList.newInstance().getWebPageParserController().
                operationChangeNavigating(false);
        this.setVisible(false);
        DynamicMapControllerList.newInstance().getWebPageParserController().
                operationParseObjects();
        this.dispose();
    } catch (Exception e) {
    }
}//GEN-LAST:event_btnProcessOutputActionPerformed

private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
    WindowListener[] listeners = getWindowListeners();
    for (int i = 0; i < listeners.length; i++) {
        this.removeWindowListener(listeners[i]);
    }
    DynamicMapControllerList.newInstance().getWebPageParserController().
            operationCloseWindow();

}//GEN-LAST:event_formWindowClosed

    @Override
    public void modelPropertyChange(PropertyChangeEvent evt) {
        if (evt.getPropertyName().equals(
                WebPageParserController.CHANGE_BROWSER_TYPE)) {
            choiceBrowserType.select(evt.getNewValue().toString());
        } else if (evt.getPropertyName().equals(
                WebPageParserController.CHANGE_DECIVE_ADDRESS)) {
            txtAddress.setText(evt.getNewValue().toString());
        } else if (evt.getPropertyName().equals(
                WebPageParserController.CHANGE_OBJECT_TYPE)) {
            choiceObjectType.select(evt.getNewValue().toString());
        } else if (evt.getPropertyName().equals(
                WebPageParserController.CHANGE_SELECTED_FRAME)) {
            txtSelectFrame.setText(evt.getNewValue().toString());
        } else if (evt.getPropertyName().equals(
                WebPageParserController.CHANGE_SELECTED_OBJECTS)) {
            txtOutput.setText(evt.getNewValue().toString());
            btnProcessOutput.setEnabled(true);
        } else if (evt.getPropertyName().equals(
                WebPageParserController.CHANGE_NAVIGATING)) {
            boolean val = Boolean.parseBoolean(evt.getNewValue().toString());
            btnEndNavigation.setEnabled(val);
            btnGetObjects.setEnabled(val);
            btnSelectFrame.setEnabled(val);
            btnStartNavigation.setEnabled(!val);
        } else if (evt.getPropertyName().equals(
                WebPageParserController.SHOW_ERROR)) {
            JOptionPane.showMessageDialog(null,
                    evt.getNewValue().toString(),
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
        } else if (evt.getPropertyName().equals(
                WebPageParserController.SHOW_WEB_PAGE_PARSER)) {
            this.centerParent();
        } else if (evt.getPropertyName().equals(
                WebPageParserController.PARSE_SELECTED_OBJECTS)) {
            if (evt.getNewValue() != null &&
                    ((LinkedList<PageParserObject>) evt.getNewValue()).size() > 0) {
                operationParseNewObject((LinkedList<PageParserObject>) evt.getNewValue());
            }
        }
    }

    public void operationParseNewObject(LinkedList<PageParserObject> list) {
        MyDefaultMutableTreeNode node = DynamicMapControllerList.newInstance().
                getDynamicMapController().operationGetSelectedNode();
        for (int i = 0; i < list.size(); i++) {
            System.out.println("PARSE ITERATION: " + (i + 1) + "  of  " + list.size());
            this.operationParseNewObject(list.get(i),
                    null,
                    node);
            //dynamicMapController.operationParseNewObject(list.get(i),node);
        }
    }

    public void operationParseNewObject(PageParserObject ppo,
            PageParserObject parentPpo,
            MyDefaultMutableTreeNode node) {
        DynamicMapController map = new DynamicMapController();
        map.operationParseNewObject(ppo,
                parentPpo,
                node);
        MyDefaultMutableTreeNode newNode = DynamicMapControllerList.newInstance().
                getDynamicMapController().operationGetSelectedNode();
        System.out.println("NEW NODE: " + newNode.getUserObject().toString());
        System.out.println("OLD NODE: " + node.getUserObject().toString());
        if (node != newNode) {
            System.out.println("THE PARENT HAS BEEN ADDED");
            if (ppo.getChilds() != null) {
                for (int j = 0; j < ppo.getChilds().size(); j++) {
                    System.out.println("CHILD NO: " + j + " IS BEING ADDED");
                    // SHOW CHILDREN AND LET THE USER SELECT THE ONES HE WANTS TO ADD
                    this.operationParseNewObject(ppo.getChilds().get(j),
                            ppo,
                            newNode);

                }
            }
        } else {
            System.out.println(
                    "THE PARENT HAS NOT BEEN ADDED. CHILDREN WILL NOT BE ADDED AS WELL");
        }
    }

    public boolean validateForm() {
        return true;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Button btnEndNavigation;
    private java.awt.Button btnGetObjects;
    private java.awt.Button btnProcessOutput;
    private java.awt.Button btnSelectFrame;
    private java.awt.Button btnStartNavigation;
    private java.awt.Choice choiceBrowserType;
    private java.awt.Choice choiceObjectType;
    private java.awt.Label lblNavigation;
    private java.awt.Label lblObjectType;
    private java.awt.Label lblOutputHeader;
    private java.awt.Label lblPageNavigationHeader;
    private java.awt.Label lblSearchObjectHeader;
    private java.awt.Label lblSelectBrowser;
    private java.awt.Label lblSelectBrowser1;
    private java.awt.Panel pnlNavigation;
    private java.awt.Panel pnlOutput;
    private java.awt.Panel pnlSearchObject;
    private java.awt.TextField txtAddress;
    private java.awt.TextArea txtOutput;
    private java.awt.TextField txtSelectFrame;
    // End of variables declaration//GEN-END:variables
}
